/**
 * Created by shenguocheng on 2016/11/4.
 */
$('#panel_db').hide();
var hive_dbdict = new Array();
var hive_tbl = new Array();

$.ajax({
    async: false, url: "/get_dict_db", context: document.body, success: function (data) {
        hive_dbdict = data.data;
        for (var i in hive_dbdict) {
            $("#databases").append("<li role='presentation'><a role='menuitem' tabindex='" + hive_dbdict[i][0] + "' href='#'>" + hive_dbdict[i][3] + "</a></li>")
        }
    }
});

if (hive_dbdict.length != 0) {

    $('ul#databases').on('click', 'li', function () {
        $('#panel_db').show();
        var current_comment = hive_dbdict[$(this).children('a').attr("tabindex")][1];
        var current_owner = hive_dbdict[$(this).children('a').attr("tabindex")][4];
        if (current_comment != null)
            $('#div_db').html("数据库名称：<b>" + $(this).children('a').text() + " </b>（创建者：" + current_owner + "，注释：" + current_comment + "）");
        else
            $('#div_db').html("数据库名称：<b>" + $(this).children('a').text() + " </b>（创建者：" + current_owner + "）");
        $('#panel_tb').hide();
        $('#tbl_columns').hide();


        <!--alert(-->
        <!--hive_dbdict[$(this).children('a').attr("tabindex")]-->
        <!--);-->

        if (hive_tbl.length == 0) {
            $.ajax({
                async: false, url: "/get_dict_tbl", context: document.body, success: function (data) {
                    hive_tbl = data.data;
                }
            });
        }
        $("#tables").empty();
        now_tbls = hive_tbl[$(this).children('a').attr("tabindex")];
        for (var i in  now_tbls) {
            $("#tables").append("<li role='presentation'><a role='menuitem' tabindex='" + now_tbls[i][0] + "' parent='" + $(this).children('a').attr("tabindex") + "' href='#'>" + now_tbls[i][7] + "</a></li>");
        }
    });
}

function getLocalTime(nS) {
    return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/, ' ');
}